import { defHttp } from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
	list = '/journey/bsTravellinePlatpretravelline/list',
	save = '/journey/bsTravellinePlatpretravelline/add',
	edit = '/journey/bsTravellinePlatpretravelline/edit',
	deleteOne = '/journey/bsTravellinePlatpretravelline/delete',
	deleteBatch = '/journey/bsTravellinePlatpretravelline/deleteBatch',
	importExcel = '/journey/bsTravellinePlatpretravelline/importExcel',
	exportXls = '/journey/bsTravellinePlatpretravelline/exportXls',
	bsTravellinePretravellinescenicgroupList = '/journey/bsTravellinePlatpretravelline/listBsTravellinePretravellinescenicgroupByMainId',
	deleteBsTravellinePretravellinescenicgroupTwoOther = '/journey/bsTravellinePlatpretravelline/deleteBsTravellinePretravellinescenicgroupTwoOther',
	bsTravellinePretravellinescenicgroupSave = '/journey/bsTravellinePlatpretravelline/addBsTravellinePretravellinescenicgroup',
	bsTravellinePretravellinescenicgroupEdit = '/journey/bsTravellinePlatpretravelline/editBsTravellinePretravellinescenicgroup',
	bsTravellinePretravellinescenicgroupDelete = '/journey/bsTravellinePlatpretravelline/deleteBsTravellinePretravellinescenicgroup',
	bsTravellinePretravellinescenicgroupDeleteBatch = '/journey/bsTravellinePlatpretravelline/deleteBatchBsTravellinePretravellinescenicgroup',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
	defHttp.get({ url: Api.list, params });

/**
 * 删除单个
 */
export const deleteOne = (params, handleSuccess) => {
	return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
		handleSuccess();
	});
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
	createConfirm({
		iconType: 'warning',
		title: '确认删除',
		content: '是否删除选中数据',
		okText: '确认',
		cancelText: '取消',
		onOk: () => {
			return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
				handleSuccess();
			});
		}
	});
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
	if (params.opened == '开启' || params.opened == 'true' || params.opened == 1) {
		params.opened = true
	} else {
		params.opened = false
	}
	params.images = JSON.stringify(params.images2.split(","))
	let extinfor = {
		preTags: params.preTags,
		startPrice: params.startPrice,
		msg: params.msg,
		preTitle: params.preTitle,
		preMsg: params.preMsg,
		historicalUserNum: params.historicalUserNum,
		preId: params.preId,
		pdtIds: params.pdtIds.split(','),
		suggestedTime: params.suggestedTime,
		difficultyLevelMsg: params.difficultyLevelMsg,
		difficultyLevel: params.difficultyLevel,
		userSelectCars: params.userSelectCars,
		userSelectCarsDetails: params.userSelectCarsDetails || '[]'
	}
	params.extinfor = JSON.stringify(extinfor)
	params.minday = params.maxday
	let url = isUpdate ? Api.edit : Api.save;
	return defHttp.post({ url: url, params });




}

/**
 * 列表接口
 * @param params
 */
export const bsTravellinePretravellinescenicgroupList = (params) => {
	if (params['travellineid']) {
		return defHttp.get({ url: Api.bsTravellinePretravellinescenicgroupList, params });
	}
	return Promise.resolve({});
}


/**
 * 删除单个
 */
export const bsTravellinePretravellinescenicgroupDelete = (params, handleSuccess) => {
	return defHttp.delete({ url: Api.bsTravellinePretravellinescenicgroupDelete, params }, { joinParamsToUrl: true }).then(() => {
		handleSuccess();
	});
}
export const deleteBsTravellinePretravellinescenicgroupTwoOtherPost = (params) => {
	return defHttp.get({ url: Api.deleteBsTravellinePretravellinescenicgroupTwoOther, params });
}
/**
 * 批量删除
 * @param params
 */
export const bsTravellinePretravellinescenicgroupDeleteBatch = (params, handleSuccess) => {
	createConfirm({
		iconType: 'warning',
		title: '确认删除',
		content: '是否删除选中数据',
		okText: '确认',
		cancelText: '取消',
		onOk: () => {
			return defHttp.delete({ url: Api.bsTravellinePretravellinescenicgroupDeleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
				handleSuccess();
			});
		}
	});
}
/**
 * 保存或者更新
 * @param params
 */
export const bsTravellinePretravellinescenicgroupSaveOrUpdate = (params, isUpdate) => {
	let url = isUpdate ? Api.bsTravellinePretravellinescenicgroupEdit : Api.bsTravellinePretravellinescenicgroupSave;
	return defHttp.post({ url: url, params });
}
/**
 * 导入
 */
export const bsTravellinePretravellinescenicgroupImportUrl = '/journey/bsTravellinePlatpretravelline/importBsTravellinePretravellinescenicgroup'

/**
 * 导出
 */
export const bsTravellinePretravellinescenicgroupExportXlsUrl = '/journey/bsTravellinePlatpretravelline/exportBsTravellinePretravellinescenicgroup'